import { createRouter, createWebHistory } from 'vue-router'

const routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/login'),
    },
    {
        path: '/admin',
        name: 'admin',
        redirect: '/admin/nodeControl',
        component: () => import('@/views/index/index'),
        children: [
            {
                path: 'nodeControl',
                name: 'nodeControl',
                component: () => import('@/views/nodeControl/nodeControl'),
            },
            {
                path: 'hotelMant',
                name: 'hotelMant',
                component: () => import('@/views/hotelMant/hotelMant'),
            },
        ]
    },
    {
        path: '/404',
        name: '404',
        component: () => import('@/views/404/404'),
    },
]
const router = new createRouter({
    history: createWebHistory(),
    routes,
})
import $store from '@/store'
router.beforeEach((to, from, next) => {
    let token = $store.state.token
    if(to.matched.length === 0){
        next({name :'404'})
    }else{
        next()
    }
})
// process.env.BASE_URL
export default router